package com.itheima.treeset;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class MyTreeSetDemo2 {
    public static void main(String[] args) {
        TreeSet<Student> treeSet=new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result=Integer.parseInt(o1.getAge())-Integer.parseInt(o2.getAge());
                return result==0?o1.getName().compareTo(o2.getName()):result;
            }
        });
        treeSet.add(new Student("yyds","18"));
        treeSet.add(new Student("yyds","10"));
        treeSet.add(new Student("yyds","11"));
        treeSet.add(new Student("yy","11"));
        treeSet.add(new Student("yyds","11"));
       // System.out.println(treemap);
        Iterator<Student> iterator=treeSet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
